import { Button, Checkbox, Form, Input } from 'antd';
import React from 'react';
import { history } from 'umi';
import http from '@/utils/request/index';
const App: React.FC = () => {
  const onFinish = (values: any) => {
    console.log('Success:', values);
    http({ url: '/login', method: 'post', data: { ...values } }).then((res) => {
      console.log(res, 'res');
      if (res.code == 0) {
        localStorage.setItem('token', 'umijs-666');
      }
      history.push('/carousel/list');
    });
  };

  const onFinishFailed = (errorInfo: any) => {
    console.log('Failed:', errorInfo);
  };

  return (
    <Form
      name="basic"
      labelCol={{ span: 8 }}
      wrapperCol={{ span: 16 }}
      initialValues={{ remember: true }}
      onFinish={onFinish}
      onFinishFailed={onFinishFailed}
      autoComplete="off"
    >
      <Form.Item
        label="用户"
        name="username"
        rules={[{ required: true, message: 'Please input your username!' }]}
      >
        <Input />
      </Form.Item>

      <Form.Item
        label="密码"
        name="password"
        rules={[{ required: true, message: 'Please input your password!' }]}
      >
        <Input.Password />
      </Form.Item>

      <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
        <Button type="primary" htmlType="submit">
          登录
        </Button>
      </Form.Item>
    </Form>
  );
};

export default App;
